package Queues;
class EmptyQueueException extends RuntimeException{
	EmptyQueueException(String err)
	{
		super(err);
	}
}
class FullQueueException extends RuntimeException{
	FullQueueException(String err)
	{
	super(err);
	}
}

interface Queue<E>{
	public boolean isEmpty();
	public boolean isFull();
	public void enQueue(E value)throws FullQueueException;
	public E deQueue()throws EmptyQueueException;
}
class ArrayQueue<E> implements Queue<E>{
	public static final int MAX=4; 
	int Rear=MAX-1;
	int Front=MAX-1;
	E QueueList[];
	
	ArrayQueue(){
		this(MAX);
		}
	
	ArrayQueue(int size){
		QueueList= (E[])new Object[size];
 	}
	public boolean isEmpty(){
		return(Rear==Front);
		
	}
	public boolean isFull(){
      return(Rear==Front);		
	}
	public void enQueue(E value)throws FullQueueException
	{
		if (Rear==MAX-1)	Rear=0; else Rear=Rear+1;
		if(isFull()) 
			{
			Rear--;
			throw new FullQueueException("Queue is Full");
			}
		else 
			QueueList[Rear]=value;
	}
	
	public E deQueue()throws EmptyQueueException{
		
		if(isEmpty()){
			throw new EmptyQueueException("Queue is Empty");
		}
		if(Front==MAX-1) Front=0; else Front++;
		E temp=QueueList[Front];
		return temp;
	}
}//End of Class ArrayQueue
public class ArrayQueueDemo {
public static void main(String[] args)
{
	ArrayQueue Q= new ArrayQueue();
	try
	{
	
	Q.enQueue('A');
	Q.enQueue('B');
	Q.enQueue('C');
	//Q.enQueue('D');
		}
	catch(FullQueueException e){
		System.out.println(e); 
	}
	try
	{
	System.out.println(Q.deQueue());
	System.out.println(Q.deQueue());
	System.out.println(Q.deQueue());
	//System.out.println(Q.deQueue());
	//System.out.println(Q.deQueue());
	}

	catch(EmptyQueueException e){
		System.out.println(e); 
	}
}
}